# 示例1：将错误和输出重定向到文件
# dir 'C:\', 'fakepath' 2>&1 > .\dir.log

# # 示例2：将所有成功流数据发送到文件
# Write-Output "This is about-Rediection"
# .\about_Redirection\Example.ps1 > Example.log

# 示例3：将成功、警告和错误流发送到文件
# &{
#     Write-Warning "hello"
#     Write-Error "hello"
#     Write-Output "h1"
# } 3>&1 2>&1 > C:\Users\31840\powershell-workspace\about_Redirection\redirection.log

# 示例4：将所有流重定向到文件
# . .\about_Redirection\Example.ps1 *> Example1.log

# 示例5：禁止显示所有Write-Host和信息流数据
# &{
#     Write-Host "Hello"
#     Write-Information "Hello" -InformationAction Continue
# } 6> $null

# 示例6：显示操作首选项的效果
$ErrorActionPreference = 'Continue'
$ErrorActionPreference > log.txt
Get-Item / not-here 2>&1 >> log.txt

$ErrorActionPreference = 'SilentlyContinue'
$ErrorActionPreference >> log.txt
Get-Item / not-here 2>&1 >> log.txt

$ErrorActionPreference = 'Stop'
$ErrorActionPreference >> .\log.txt
try {
    Get-Item / not-here 2>&1 >> .\log.txt
}
catch {
    "`tError caught!" >> .\log.txt
}

$ErrorActionPreference = 'Ignore'
$ErrorActionPreference >> .\log.txt
Get-Item / not-here 2>&1 >> .\log.txt

$ErrorActionPreference = 'Inquire'
$ErrorActionPreference >> .\log.txt
Get-Item / not-here 2>&1 >> .\log.txt

$ErrorActionPreference = 'Continue'